﻿using System;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace SharingCenter.Web
{
    public class FileHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
            Image img = Image.FromStream(context.Request.Files[0].InputStream);
            //string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();
            //string strSaveLocation = context.Server.MapPath("~/Content/images/uploads") + "" + Guid.NewGuid() + strExtension;
            img.Save(context.Server.MapPath("~/Content/images/uploads") + "" + Guid.NewGuid() + ".jpg", ImageFormat.Jpeg);
            //context.Request.Files[0].SaveAs(strSaveLocation);
            context.Response.StatusCode = 200;
            context.Response.ContentType = "text/plain";
            context.Response.Write(strFileName);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}